<?php
/**
 * Created by PhpStorm.
 * User: liuhong
 * Date: 2019-04-09
 * Time: 16:54
 */

namespace app\service;


use app\common\model\Video;
use think\Db;
use think\Exception;

use GuzzleHttp\Client;

/**
 * 课程列表
 * Class VideoService
 * @package app\service
 */
class VideoService  extends BaseService
{
    public $videoModel;

    public function __construct()
    {
        $this->videoModel = new Video();
    }

    /**
     * 查询
     * @param $where
     * @param $page
     * @param int $page_num
     * @param string $filed
     * @return array|bool
     */
    public function queryPage($where,$page,$page_num=20,$filed='*',$order='a.ord desc'){
        try{
            $data = $this->videoModel
                ->alias('a')
                ->join('zkhb_video_cate b','a.cate_id=b.id','left')
                ->order($order)
                ->field($filed)
                ->where($where)
                ->page($page,$page_num)
                ->select();
            if ($data){
                $data = $data->toArray();
            }
            return $data;
        }catch (Exception $ex){
            LogService::S()->writeLog('Exception',$ex->getMessage());
            return false;
        }
    }

    /**
     * 查询数量
     * @param $where
     * @return bool|int|string
     */
    public function queryCount($where)
    {
        try {
            return $this->videoModel
                ->alias('a')
                ->join('zkhb_video_cate b','a.cate_id=b.id','left')
                ->order('a.id desc')
                ->where($where)
                ->count();
        } catch (Exception $ex) {
            LogService::S()->writeLog('Exception', $ex->getMessage());
            return false;
        }
    }
}